// pages/goods_detail/index.js

import { api } from '../../request/index.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsInfo:{}
  },
  goodsInfo:{},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {goods_id} = options
    this.getGoodsDetail(goods_id)
  },

  // 获取商品详情
  async getGoodsDetail(goods_id){
    const {message} = await  api({url:"/goods/detail",data:{goods_id}})
    this.goodsInfo = message
    this.setData({
      goodsInfo:{
        pics:message.pics,
        goods_price:message.goods_price,
        goods_name:message.goods_name,
        goods_introduce:message.goods_introduce.replace(/\.webp/g,'.jpg')
      }
    })
  },
  handleImagePriview(e){
    const urls = this.goodsInfo.pics.map(v=>v.pics_mid)
    const current = e.currentTarget.dataset.url
    console.log(current);
    wx.previewImage({
      current,
      urls
    });
  }
})